local mochou = fk.CreateSkill {
  name = "lingling__mochou",
}

Fk:loadTranslationTable{
  ["lingling__mochou"] = "莫愁",
  [":lingling__mochou"] = "结束阶段，若你没有手牌，你可以对攻击范围内的一名角色造成1点伤害，然后其选择令你摸两张牌或再受到你造成的1点伤害。",

  ["#lingling__mochou-choose"] = "莫愁：对一名角色造成1点伤害，其选择令你摸两张牌或再受到1点伤害",
  ["lingling__mochou_draw"] = "%src摸两张牌",
  ["lingling__mochou_damage"] = "%src再对你造成1点伤害",
}

mochou:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(mochou.name) and player.phase == Player.Finish and
      player:isKongcheng() and
      table.find(player.room.alive_players, function (p)
        return player:inMyAttackRange(p)
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
        return player:inMyAttackRange(p)
      end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = mochou.name,
      prompt = "#lingling__mochou-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:damage{
      from = player,
      to = to,
      damage = 1,
      skillName = mochou.name,
    }
    if player.dead or to.dead then return end
    local choice = room:askToChoice(to, {
      choices = {
        "lingling__mochou_draw:"..player.id,
        "lingling__mochou_damage:"..player.id,
      },
      skill_name = mochou.name,
    })
    if choice:startsWith("lingling__mochou_damage") then
      room:damage{
        from = player,
        to = to,
        damage = 1,
        skillName = mochou.name,
      }
    else
      player:drawCards(2, mochou.name)
    end
  end,
})

return mochou
